//
//  ZMyOrderInfoCell.m
//  DistributorAB
//
//  Created by LZY on 2019/10/14.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZMyOrderInfoCell.h"

@interface ZMyOrderInfoCell ()
@property (nonatomic, strong) UIImageView *ivShop;//产品图片
@property (nonatomic, strong) UILabel *lblName;//产品名称

//类型
@property (nonatomic, strong) UILabel *lblNoticeType;
@property (nonatomic, strong) UILabel *lblType;

@property (nonatomic, strong) UILabel *lblNumber;//数量
@property (nonatomic, strong) UILabel *lblValidity;//有效期
@property (nonatomic, strong) UILabel *lblExpiration;//质保期
@property (nonatomic, strong) UILabel *lblPay;//赔付金
@property (nonatomic, strong) UILabel *lblPrice;//单价(省级经销商)
@property (nonatomic, strong) UILabel *lblTotal;//总计(省级经销商)

@property (nonatomic, strong) UILabel *lblNoticeValidity;//有效期文字
@property (nonatomic, strong)UILabel *lblNoticePay;//补贴工时费文字
//详情界面
@property (nonatomic, strong) UIButton *btnCancel;//取消预订
@property (nonatomic, strong) UIButton *btnChange;//修改数量
@property (nonatomic, strong) UILabel *lblCancel;//已取消
@end

@implementation ZMyOrderInfoCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局
- (void)setupViewAction{
    _ivShop = [[UIImageView alloc] initWithFrame:CGRectMake(8, 10, 90, 90)];
    _ivShop.backgroundColor = kColorWithHex(0xf2f2f2);
    _ivShop.contentMode = UIViewContentModeScaleToFill;
    [self.contentView addSubview:_ivShop];
    
    _lblName = [UILabel new];
    _lblName.font = [UIFont systemFontOfSize:14];
    _lblName.textColor = kColorWithHex(0x333333);
    _lblName.preferredMaxLayoutWidth = kScreen_Width - 137;
    _lblName.numberOfLines = 2;
    [self.contentView addSubview:_lblName];
    [_lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.ivShop.mas_top);
        make.leading.equalTo(self.ivShop.mas_trailing).offset(13);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-26);
    }];
    
    _lblNoticeType = [UILabel new];
    [self.contentView addSubview:_lblNoticeType];
    [_lblNoticeType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lblName.mas_bottom).offset(14);
        make.leading.equalTo(self.lblName.mas_leading);
        make.size.mas_equalTo(CGSizeMake(48, 17));
    }];
    
    _lblType = [UILabel new];
    [self.contentView addSubview:_lblType];
    [_lblType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lblNoticeType.mas_centerY);
        make.leading.equalTo(self.lblNoticeType.mas_trailing).offset(10);
        make.trailing.equalTo(self.lblName.mas_trailing);
        make.height.equalTo(self.lblNoticeType.mas_height);
    }];
    CGFloat numberHeight = 0;
    if (AGENT_LEVEL == 1) {
        numberHeight = 0;
        UILabel *lblNoticeNumber = [[UILabel alloc] initWithFrame:CGRectMake(24, 115, 60, 20)];
        lblNoticeNumber.text = @"预订数量";
        lblNoticeNumber.font = [UIFont systemFontOfSize:14];
        lblNoticeNumber.textColor = kColorWithHex(0x333333);
        [self.contentView addSubview:lblNoticeNumber];
        _lblNumber = [[UILabel alloc] initWithFrame:CGRectMake(128, 115, kScreen_Width - 144, 20)];
        _lblNumber.font = [UIFont systemFontOfSize:14];
        _lblNumber.textColor = kColorWithHex(0x4a4a4a);
        [self.contentView addSubview:_lblNumber];
        UIView *viewLineOne = [[UIView alloc] initWithFrame:CGRectMake(24, 142, kScreen_Width - 24, 1)];
        viewLineOne.backgroundColor = kColorWithHex(0xf2f2f2);
        [self.contentView addSubview:viewLineOne];
    }else{
        numberHeight = 35;
    }
    
    _lblNoticeValidity = [[UILabel alloc] initWithFrame:CGRectMake(24, 150 - numberHeight, 60, 20)];
    _lblNoticeValidity.text = @"有效期";
    _lblNoticeValidity.font = [UIFont systemFontOfSize:14];
    _lblNoticeValidity.textColor = kColorWithHex(0x333333);
    [self.contentView addSubview:_lblNoticeValidity];
    
    _lblValidity = [[UILabel alloc] initWithFrame:CGRectMake(128, 150 - numberHeight, kScreen_Width - 144, 20)];
    _lblValidity.font = [UIFont systemFontOfSize:14];
    _lblValidity.textColor = kColorWithHex(0x4a4a4a);
    [self.contentView addSubview:_lblValidity];
    UIView *viewLineTwo = [[UIView alloc] initWithFrame:CGRectMake(24, 177 - numberHeight, kScreen_Width - 24, 1)];
    viewLineTwo.backgroundColor = kColorWithHex(0xf2f2f2);
    [self.contentView addSubview:viewLineTwo];
    
    UILabel *lblNoticeExpiration = [[UILabel alloc] initWithFrame:CGRectMake(24, 185 - numberHeight, 60, 20)];
    lblNoticeExpiration.text = @"质保期";
    lblNoticeExpiration.font = [UIFont systemFontOfSize:14];
    lblNoticeExpiration.textColor = kColorWithHex(0x333333);
    [self.contentView addSubview:lblNoticeExpiration];
    _lblExpiration = [[UILabel alloc] initWithFrame:CGRectMake(128, 185 - numberHeight, kScreen_Width - 144, 20)];
    _lblExpiration.font = [UIFont systemFontOfSize:14];
    _lblExpiration.textColor = kColorWithHex(0x4a4a4a);
    [self.contentView addSubview:_lblExpiration];
    UIView *viewLineThree = [[UIView alloc] initWithFrame:CGRectMake(24, 212 - numberHeight, kScreen_Width - 24, 1)];
    viewLineThree.backgroundColor = kColorWithHex(0xf2f2f2);
    [self.contentView addSubview:viewLineThree];
    
    
    _lblNoticePay = [[UILabel alloc] initWithFrame:CGRectMake(24, 220 - numberHeight, 80, 20)];
    _lblNoticePay.text = @"补贴工时费";
    _lblNoticePay.font = [UIFont systemFontOfSize:14];
    _lblNoticePay.textColor = kColorWithHex(0xca9f61);
    [self.contentView addSubview:_lblNoticePay];
   
    _lblPay = [[UILabel alloc] initWithFrame:CGRectMake(128, 220 - numberHeight, kScreen_Width - 144, 20)];
    _lblPay.font = [UIFont systemFontOfSize:14];
    _lblPay.textColor = kColorWithHex(0xca9f61);
    [self.contentView addSubview:_lblPay];
    
    if (AGENT_LEVEL == 1) {
        
        _lblPrice = [UILabel new];
        _lblPrice.font = [UIFont boldSystemFontOfSize:16];
        _lblPrice.textColor = kColorWithHex(0x70be68);
        [self.contentView addSubview:_lblPrice];
        [_lblPrice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.lblNumber.mas_centerY);
            make.trailing.equalTo(self.contentView.mas_trailing).offset(-26);
            make.height.mas_equalTo(22);
        }];
        
        UIView *viewLine = [[UIView alloc] initWithFrame:CGRectMake(0, 247, kScreen_Width, 1)];
        viewLine.backgroundColor = kColorWithHex(0xf2f2f2);
        [self.contentView addSubview:viewLine];
        
        UILabel *lblNoticeTotal = [[UILabel alloc] initWithFrame:CGRectMake(24, 257, 60, 22)];
        lblNoticeTotal.text = @"总计";
        lblNoticeTotal.font = [UIFont boldSystemFontOfSize:16];
        lblNoticeTotal.textColor = kColorWithHex(0x70be68);
        [self.contentView addSubview:lblNoticeTotal];
        
        _lblTotal = [[UILabel alloc] initWithFrame:CGRectMake(128, 257, kScreen_Width - 144, 22)];
        _lblTotal.font = [UIFont boldSystemFontOfSize:16];
        _lblTotal.textColor = kColorWithHex(0x70be68);
        [self.contentView addSubview:_lblTotal];
    }
    
    
}
#pragma mark - 数据更新
- (void)setPartModel:(BShopPartModel *)partModel{
    if (partModel) {
        _partModel = partModel;
        [HFTools imageViewUpdateWithUrl:partModel.image_url withImageView:_ivShop withPlaceholderImage:@""];
        _lblName.text = partModel.parts_name;
        _lblType.text = partModel.name;
        _lblNumber.text = partModel.count;
        
        _lblValidity.text = [NSString stringWithFormat:@"自出厂日期有效期为%@个月",partModel.install];
        
        _lblExpiration.text = [NSString stringWithFormat:@"%@个月",partModel.warranty];
        _lblPay.text = [NSString stringWithFormat:@"￥%@/个",partModel.compensationPrice];
        //有效期数值为0 补贴工时费 数值为0 不显示
        if ([partModel.install integerValue]==0) {
            _lblValidity.hidden = YES;
            _lblNoticeValidity.hidden = YES;
        }
        if ([partModel.compensationPrice integerValue]==0) {
            _lblPay.hidden = YES;
            _lblNoticePay.hidden = YES;
        }
        if (AGENT_LEVEL == 1) {
            _lblPrice.text = [NSString stringWithFormat:@"￥%@/件",partModel.salePrice];
            NSInteger count = [partModel.count integerValue];
            CGFloat price = [partModel.salePrice floatValue];
            _lblTotal.text = [NSString stringWithFormat:@"￥%.2f",count * price];
        }
        
        if (_isOrderDetail) {
            if ([partModel.state isEqualToString:@"1"]) {
                _btnCancel.hidden = NO;
                _btnChange.hidden = NO;
                _lblCancel.hidden = YES;
            }else{
                _btnCancel.hidden = YES;
                _btnChange.hidden = YES;
                _lblCancel.hidden = NO;
            }
        }
        //市县级隐藏数量相关
        if(AGENT_LEVEL != 1 )
        {
            _btnChange.hidden = YES;
        }
    }
}
- (void)setIsOrderDetail:(BOOL)isOrderDetail{
    _isOrderDetail = isOrderDetail;
    
    if (self.isOrderDetail) {
        _lblType.font = [UIFont systemFontOfSize:14];
        _lblType.textColor = kColorWithHex(0x272727);
    }else{
        _lblType.font = [UIFont systemFontOfSize:12];
        _lblType.textColor = kColorWithHex(0x333333);
    }
    
    if (self.isOrderDetail) {
        _lblNoticeType.text = @"型号";
        _lblNoticeType.font = [UIFont systemFontOfSize:14];
        _lblNoticeType.textColor = kColorWithHex(0x666666);
        [_lblNoticeType mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(30, 19));
        }];
    }else{
        _lblNoticeType.text = @"已选择:";
        _lblNoticeType.font = [UIFont systemFontOfSize:12];
        _lblNoticeType.textColor = kColorWithHex(0x979797);
    }
    
    if (_isOrderDetail) {
        _btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnCancel setImage:imgname(@"order_cancel_icon") forState:UIControlStateNormal];
        [_btnCancel addTarget:self action:@selector(btnCancelClickAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_btnCancel];
        [_btnCancel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-12);
            make.trailing.equalTo(self.contentView.mas_trailing).offset(-16);
            make.size.mas_equalTo(CGSizeMake(69, 26));
        }];
        
        _btnChange = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnChange setImage:imgname(@"order_change_number_icon") forState:UIControlStateNormal];
        [_btnChange addTarget:self action:@selector(btnChangeClickAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_btnChange];
        [_btnChange mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-12);
            make.trailing.equalTo(self.btnCancel.mas_leading).offset(-8);
            make.size.mas_equalTo(CGSizeMake(69, 26));
        }];
        
        _lblCancel = [UILabel new];
        _lblCancel.text = @"已取消";
        _lblCancel.font = [UIFont systemFontOfSize:14];
        _lblCancel.textColor = kColorWithHex(0xd84b4a);
        [self.contentView addSubview:_lblCancel];
        [_lblCancel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-12);
            make.trailing.equalTo(self.contentView.mas_trailing).offset(-29);
            make.height.mas_equalTo(20);
        }];
        
        UIView *viewLineFour;
        if (AGENT_LEVEL == 1) {
            viewLineFour = [[UIView alloc] initWithFrame:CGRectMake(0, 289, kScreen_Width, 1)];
        }else{
            viewLineFour = [[UIView alloc] initWithFrame:CGRectMake(0, 284 - 35, kScreen_Width, 2)];
        }
        viewLineFour.backgroundColor = kColorWithHex(0xf2f2f2);
        [self.contentView addSubview:viewLineFour];
        
        if (AGENT_LEVEL == 1) {
            UIView *viewLine = [[UIView alloc] initWithFrame:CGRectMake(0, 348, kScreen_Width, 2)];
            viewLine.backgroundColor = kColorWithHex(0xf2f2f2);
            [self.contentView addSubview:viewLine];
        }
        
    }else{
        
        UIView *viewLineFour;
        if (AGENT_LEVEL == 1) {
            viewLineFour = [[UIView alloc] initWithFrame:CGRectMake(0, 287, kScreen_Width, 10)];
        }else{
            viewLineFour = [[UIView alloc] initWithFrame:CGRectMake(0, 253 - 35, kScreen_Width, 10)];
        }
        viewLineFour.backgroundColor = kColorWithHex(0xf2f2f2);
        [self.contentView addSubview:viewLineFour];
        
    }
}
#pragma mark - 交互事件
- (void)btnCancelClickAction:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(orderInfoCellBtnCancelClick:)]) {
        [self.delegate orderInfoCellBtnCancelClick:self.indexPath];
    }
}
- (void)btnChangeClickAction:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(orderInfoCellBtnChangeClick:)]) {
        [self.delegate orderInfoCellBtnChangeClick:self.indexPath];
    }
}
+ (CGFloat)cellHeight{
    if (AGENT_LEVEL == 1) {
        return 297.0;
    }else{
        return 263.0 - 35;
    }
}
+ (CGFloat)cellDetailHeight{
    if (AGENT_LEVEL == 1) {
        return 350.0;
    }else{
        return 286.0 - 35;
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
